package model

import (
	"time"
)

// SignLogs SignLogs用户
type SignLogs struct {
	Id      int       `xorm:"INT(11) PK AUTOINCR comment('主键')" json:"id"` //主键
	UserId  int       `xorm:"INT(11)" json:"user_id"`
	User    *User     `xorm:"-" json:"user"`
	Created time.Time `xorm:"DATETIME INDEX" json:"created"`
	Updated time.Time `xorm:"DATETIME" json:"updated"`
}

func (SignLogs) TableName() string {
	return "sys_sign_logs"
}

// SignGetToday SignGet 单条用户信息
func SignGetToday(uid int) (*SignLogs, bool) {
	mod := &SignLogs{}
	has, _ := db.Where("user_id = ?", uid).Where("TO_DAYS(created) = TO_DAYS(NOW())").Get(mod)
	return mod, has
}

func SignAdd(mod *SignLogs) error {
	sess := db.NewSession()
	defer sess.Close()
	sess.Begin()
	if _, err := sess.Insert(mod); err != nil {
		sess.Rollback()
		return err
	}
	sess.Commit()
	return nil
}
